package com.work.service.main.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.work.constant.ExceptionDescription;
import com.work.dto.main.TShipBillRemarkSearchDTO;
import com.work.dto.main.TShipBillRemarkSubmitDTO;
import com.work.entity.main.TShipBillRemark;
import com.work.mapper.main.TShipBillRemarkMapper;
import com.work.service.main.ITShipBillRemarkService;
import com.work.vo.main.TShipBillRemarkVO;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 理货舱单交班记录接口实现
 *
 * @author ：dujianyu
 * @since ：Created in 2024/3/22 16:26
 */
@AllArgsConstructor
@Service
public class TShipBillRemarkServiceImpl extends BaseServiceImpl<TShipBillRemarkMapper, TShipBillRemark> implements ITShipBillRemarkService {
    @Override
    public boolean submitShipBillRemark(TShipBillRemarkSubmitDTO dto) {
        if (Func.isNull(dto.getRemark()) || Func.isBlank(dto.getRemark())) {
            return true;
        }

        TShipBillRemark entity = BeanUtil.copy(dto, TShipBillRemark.class);
        if (Func.isNull(entity)) {
            throw new RuntimeException(ExceptionDescription.FUN_ERROR + "submitTShipBillRemark-BeanUtil.copy复制失败");
        }
        entity.setCreateUserName(AuthUtil.getUserName());
        return super.saveOrUpdate(entity);
    }

    @Override
    public List<TShipBillRemarkVO> selectShipBillRemarkList(TShipBillRemarkSearchDTO dto) {
        return baseMapper.selectShipBillRemarkList(dto, null);
    }

    @Override
    public IPage<TShipBillRemarkVO> selectShipBillRemarkPage(IPage<TShipBillRemarkVO> page, TShipBillRemarkSearchDTO dto) {
        List<TShipBillRemarkVO> data = baseMapper.selectShipBillRemarkList(dto, page);
        return page.setRecords(data);
    }
}
